package com.dubbo.service.consumer;

import com.dubbo.service.HelloService;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author: wudong
 * @create: 2022-02-16 09:30
 **/
@Service
public class ConsumerService{
    // @Reference
    @Reference(methods = {@Method(name = "methodB",async = true)})
    private HelloService helloService;


    public String methodA() {
        return helloService.methodA();
    }


    public String methodB() throws ExecutionException, InterruptedException {
        helloService.methodB();
        CompletableFuture<String> helloFuture = RpcContext.getContext().getCompletableFuture();
        return helloFuture.get();
    }


    public String methodC() {
        return helloService.methodC();
    }
}
